<#include "common_var.include"/> 
<%@ page language="java" pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@include file="/common/header.jsp" %>

<#if (subClazzes?size > 1)>
<%@include file="/common/gridheader.jsp" %>
<link rel="stylesheet" type="text/css" href="<@jspEl 'ctx'/>/scripts/TabPanel/TabPanel.css"/>
<script type="text/javascript" src="<@jspEl 'ctx'/>/scripts/TabPanel/Fader.js"></script>
<script type="text/javascript" src="<@jspEl 'ctx'/>/scripts/TabPanel/TabPanel.js"></script>
</#if>

<script type="text/javascript">
	$(document).ready(function() {
		//校验 
		$("#editFormId").validationEngine('detach');	
	});
	function doAction(act){
		var recordId = $(":input[name='recordId']").val();
		
		if('return'==act||'close'==act){
			//location.href='${classNameLower}Action.action';
			art.dialog.close();
		}else if('save'==act){
			$("#editFormId").attr('action','${classNameLower}Action!save.action');
			
			<#if (subClazzes?size > 0)>
			var flag = true;
			<#list subClazzes as subClazz> 
			flag = flag && validateGrid(${subClazz.className?uncap_first}Grid);
			</#list>
			
			if(true===flag){
				<#list subClazzes as subClazz> 
				setGridValueToForm(${subClazz.className?uncap_first}Grid);
				</#list>
				submitForm('editFormId');
			}
			<#else>
			submitForm('editFormId');
			</#if>
		}else if("del"==act&&confirmDlg('是否删除该记录')){
			showWaitDialog();
			$.post('${classNameLower}Action!delete.action',{'recordId':recordId},
						function(data){
							hideWaitDialog();
							alertDlg(data);
							art.dialog.close();
						});
			return;
		}else if("edit"==act){
			var url = '${classNameLower}Action!input.action';
			$("#editFormId").attr('action',url);
 			submitForm('editFormId');
			return ;
		
		}else if(act=='audit'){
	 		if(confirm('是否审核')){
	 			$("#editFormId").attr('action','${classNameLower}Action!audit.action');
	 			submitForm('editFormId');
	 	  	}
		}else if(act=='cancelAudit'){
	 		if(confirm('是否取消审核')){
	 			$("#editFormId").attr('action','${classNameLower}Action!cacelAudit.action');
	 			submitForm('editFormId');
	 	  	}
		}
	}
	//表格按钮事件
	<#list subClazzes as subClazz>
	function do${subClazz.className}GridAction(act,selRecords){
		if('add' == act){return true;}
		if('del' == act){return true;}
	}
	</#list>
</script>
</head>

<body>
	<div class="topnav"><p>模块 &gt;资源 &gt;资源&gt;${entityCnName} 编辑</p></div>
 	
 	<fktag:toolbar>
 		<fktag:toolItem cssClass="icon-back-big" onclick="doAction('return')" title="返回列表"></fktag:toolItem>
 		<fktag:toolItem isSaveItem="true" cssClass="icon-save-big" onclick="doAction('save')"
 			editAble="<@jspEl "func == 'ADD' || func == 'EDIT'"/>" title="保存">
 		</fktag:toolItem>
 		<fktag:toolItem cssClass="icon-edit-big" editAble="<@jspEl "func == 'VIEW'"/>" onclick="doAction('edit')" title="修改"></fktag:toolItem>
 		<fktag:toolItem cssClass="icon-delete-big" editAble="<@jspEl "func == 'VIEW'"/>" onclick="doAction('del')" title="删除"></fktag:toolItem>
 		<fktag:toolItem cssClass="icon-audit-big" editAble="<@jspEl "func == 'VIEW' && entity.state == '0'"/>" onclick="doAction('audit')" title="审核"></fktag:toolItem>
 	</fktag:toolbar>
 	

 	<div class="contant">
   	<form action="${classNameLower}Action!save.action" id="editFormId" method="post">
		<input type="hidden"  name="recordId" value="<@jspEl "recordId"/>" />
		<input type="hidden"  name="func" value="<@jspEl "func"/>" />
		<input type="hidden"  name="entity.${tableClazz.pkProp.name}" value="<@jspEl "entity.${tableClazz.pkProp.name}"/>" />
		<#list tableClazz.columns as prop>
    	<#if prop.name = "versionNo">
		<input type="hidden"  name="entity.versionNo" value="<@jspEl "entity.versionNo"/>" />
		</#if>
		</#list>
		<fieldset>
		<legend>主信息</legend>
		<#assign porpNo = 0>
		<table class="formTable">
		<#list tableClazz.getEditCols() as prop>
	<#-- 过滤掉不用的字段 -->
	<#if (!prop.propName?ends_with("remark")) && prop.propName != "versionNo" && prop.propName != "class" 
		&& prop.propName != "updateUser" && prop.propName != "updateTime" && prop.propName != "createTime" && prop.propName != "createUser"
		&&prop.editor.editTypeCode != "textarea">
	<#assign porpNo=porpNo+1><#if (porpNo==1 || (porpNo-1) % 3 ==0)><tr></#if>
	<#if prop.editor.editTypeCode=='date'||prop.editor.editTypeCode=='datetime'>	    	  
	  	<td class="labelStyle"><label>${prop.propCnName}<#if prop.isEditRequired()><span>*</span></#if></label></td>
	    <td>
	    	<input id="eId${prop.propName?cap_first}" name="entity.${prop.propName}" type="text" style="width:120px;" class="Wdate ${prop.ruleHtml}" 
	    		onclick="WdatePicker({dateFmt:'yyyy-MM-dd<#if prop.editor.editTypeCode=="datetime"> HH:mm</#if>'})">
	    		<fmt:formatDate value="<@jspEl 'entity.${prop.propName}'/>" pattern ="yyyy-MM-dd<#if prop.editor.editTypeCode=="datetime"> HH:mm</#if>"/>
	    	</input>
	    </td>
	<#elseif prop.editor.editTypeCode=='dialog'>
	   	<td class="labelStyle"><label>${prop.propCnName}<#if prop.isEditRequired()><span>*</span></#if></label></td>
	    <td>
	    	<input id='eId${prop.idLabel?cap_first}Name' name="entity.${prop.idLabel?cap_first}Name" value="<@jspEl 'entity.${prop.idLabel?cap_first}Name'/>"  class="${prop.ruleHtml} inputStyle" type="text" />	
	   		<a class="selectedIco" href="#" onclick="open${prop.idLabel?cap_first}Dialog('eId${prop.propName?cap_first}','eId${prop.idLabel?cap_first}Name');"></a>
	    	<input id='eId${prop.propName?cap_first}' name="entity.${prop.propName}" value="<@jspEl 'entity.${prop.propName}'/>" type="hidden"/>	
	   	</td>
	<#elseif prop.editor.editTypeCode=='select'>
		<td class="labelStyle"><label>${prop.propCnName}<#if prop.isEditRequired()><span>*</span></#if></label></td>
		<td>
			<s:select id='eId${prop.propName?cap_first}' name="entity.${prop.propName}" list="${prop.idLabel}Map" cssClass="inputStyle ${prop.ruleHtml}" cssStyle="width:122px"<#if prop.isEditRequired()> headerKey="" headerValue=""</#if>></s:select>
		</td>
	<#else>
	   	<td class="labelStyle"><label>${prop.propCnName}<#if prop.isEditRequired()><span>*</span></#if></label></td>
	    <td>
	    	<input id='eId${prop.propName?cap_first}' name="entity.${prop.propName}" value="<@jspEl 'entity.${prop.propName}'/>" class="${prop.ruleHtml} inputStyle" type="text" />
	    </td>
	</#if>
	<#if (porpNo!=1 && porpNo % 3 ==0)></tr></#if>
	</#if>
	<#if (porpNo%3 !=0 && !prop_has_next)></tr></#if> 
	</#list>
	   
	
		<#--备注单独一行显示 -->
		<#list tableClazz.getEditCols() as prop>
    	<#if prop.editor.editTypeCode=='textarea'>
		<tr>
		<td class="labelStyle"><label>${prop.cnName}</label><#if prop.isEditRequired()><span>*</span></#if></td>
		<td style="width:320px;" colspan="5">
	   		<textarea id="eId${prop.name?cap_first}" cols="72" rows="3" class="${prop.ruleHtml}" name="entity.${prop.name}">
	   			<@jspEl "entity.${prop.name}"/>
	   		</textarea>
		</td>
		</tr>
		</#if>
		</#list>
		</table>
		</fieldset>
	</form>
   	</div>


<!--  -->
<#list subClazzes as subClazz>
<#if (subClazzes?size == 1)>
<div class="wrapper" id="domdiv_gridId${subClazz.className}">
<div class="title">明细信息</div>
<div id='dom_gridId${subClazz.className}'></div>
</div>
</#if>

<sg:grid id="${subClazz.className?uncap_first}Grid"  container="dom_gridId${subClazz.className}"  uniqueField="${subClazz.pkProp.name}"
	editable="${r"${"}(func =='ADD'||func =='EDIT')?'true':'false'}" 
	gridData="<@jspEl '${subClazz.className?uncap_first}GridInfo'/>"
	defaultRecord="<@jspEl '${subClazz.className?uncap_first}GridInfo.defVO'/>"
	toolbarAction="do${subClazz.className}GridAction"
	submitForm="editFormId">
<#list subClazz.columns as prop>
<#if prop.name != "class">
	<#if prop.name = subClazz.pkProp.name >	
	<sg:column id="${subClazz.pkProp.name}" fieldName="${subClazz.pkProp.name}" fieldType="int" header="ID" editable="false" hidden="true"></sg:column>
	<#else>
	<sg:column  header="${prop.cnName}" id="${prop.name}" fieldName="${prop.name}"
		<#if prop.javaType == 'Date'>	
			fieldType="date" format="dateTime" editType="date"></sg:column>	
		<#elseif prop.name?ends_with("Id")>
			fieldType="int" editType="" ></sg:column>
		<#elseif prop.javaType =='Decimal'>   	
			fieldType="float" editType="NumText(12,3)" format="0.000" validRule="['F']"></sg:column>
		<#elseif prop.name?ends_with("remark")>
			editType="textarea"></sg:column>
		<#else>
			editType="text(30)"></sg:column>
		</#if>
	</#if>
</#if>
</#list>
</sg:grid>
</#list>

<#if (subClazzes?size > 1)>
<div id="tab"></div>
<script type="text/javascript">
var jcTabs = [<#list subClazzes as subClazz>
				'<div class="wrapper" id="domdiv_gridId${subClazz.className}"><div class="title">明细信息</div><div id="dom_gridId${subClazz.className}"></div>'<#if subClazz_has_next>,</#if>
			</#list>];
var tabpanel = new TabPanel({active:0,renderTo:'tab',height:'300px',border:'2',autoResizable:true,
    items : [<#list subClazzes as subClazz>
             {id:'tabId${subClazz.className}',title:'明细${subClazz_index+1}',html:jcTabs[${subClazz_index}],closable: false}<#if subClazz_has_next>,</#if>
	</#list>]});
</script>
</#if>
<jsp:include page="/common/show_action_message.jsp"></jsp:include>  
</body>
</html>